package log

import "sync"

const (
	watcherBufferSize = 4096
)

type Watcher struct {
	Msg           chan *Entry
	Err           chan error
	closeNotifier chan struct{}
	closeOnce     sync.Once // 只能关一次
}

func NewWatcher() *Watcher {
	return &Watcher{
		Msg:           make(chan *Entry, watcherBufferSize),
		Err:           make(chan error, 1),
		closeNotifier: make(chan struct{}),
	}
}

func (w *Watcher) Close() {
	// 只能关一次
	w.closeOnce.Do(func() {
		close(w.closeNotifier)
	})
}
